package model

import (
	"api_gateway/global"
	"gorm.io/gorm"
	"time"
)

type Test struct {
	Id          uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId      uint           `gorm:"column:user_id;type:bigint;not null;" json:"user_id"`
	PaperId     uint           `gorm:"column:paper_id;type:bigint;not null;" json:"paper_id"`
	ProjectName string         `gorm:"column:project_name;type:varchar(20);not null;" json:"project_name"`
	TestName    string         `gorm:"column:test_name;type:varchar(20);not null;" json:"test_name"`
	Cate        string         `gorm:"column:cate;type:varchar(20);not null;" json:"cate"`
	Name        string         `gorm:"column:name;type:varchar(20);not null;" json:"name"`
	CTime       string         `gorm:"column:c_time;type:varchar(20);not null;" json:"c_time"`
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (t *Test) TableName() string {
	return "test"
}

func (t *Test) Create() error {
	return global.DB.Create(&t).Error
}

func (t *Test) Info(project_name string) error {
	return global.DB.Where("project_name=?", project_name).Limit(1).First(&t).Error
}

func (t *Test) InfoTes(id string) error {
	return global.DB.Where("id=?", id).Limit(1).First(&t).Error
}

func (t *Test) InfoTe(user_id string) error {
	return global.DB.Where("user_id=?", user_id).Limit(1).First(&t).Error
}

func (t *Test) ITest(test_status string) error {
	return global.DB.Where("test_status=?", test_status).Limit(1).First(&t).Error
}
